package org.mm.proxycache.http.codec;

import static com.google.common.base.Objects.nonNull;

import org.mm.proxycache.http.HttpResponseStatus;
import org.mm.proxycache.http.MutableHttpResponse;

import com.sleepycat.persist.model.Persistent;

@Persistent
public class DefaultHttpResponse extends DefaultHttpMessage implements MutableHttpResponse
{
    private HttpResponseStatus status = HttpResponseStatus.OK;
    private String reason = HttpResponseStatus.OK.getDescription();
    
    /*
     * (non-Javadoc)
     * 
     * @see org.mm.proxycache.http.MutableHttpResponse#duplicate()
     */
    public MutableHttpResponse duplicate()
    {
        DefaultHttpResponse response = new DefaultHttpResponse();
        response.version( httpVersion );
        response.headers.putAll( headers );
        response.status( status, reason );
        return response;
    }
    
    public void status( HttpResponseStatus status )
    {
        this.status = nonNull( status );
        this.reason = status.getDescription();
    }
    
    public void status( HttpResponseStatus status, String reason )
    {
        status( status );
        statusReasonPhrase( reason );
    }
    
    public void statusReasonPhrase( String reason )
    {
        this.reason = nonNull( reason );
    }
    
    public HttpResponseStatus status()
    {
        return status;
    }
    
    public String statusReasonPhrase()
    {
        return reason;
    }
    
}
